/**
 * @FileName: NettyServerRpcHandler.java
 * @Package: com.ziroom.sms.std.netty
 * @author liusq23
 * @created 2017/6/15 下午10:19
 * <p>
 * Copyright 2015 ziroom
 */
package com.ziroom.sms.std.netty;

import com.ziroom.sms.std.rpc.Invocation;
import com.ziroom.sms.std.rpc.RPCException;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import org.junit.Assert;

import java.lang.reflect.Method;

/**
 * <p></p>
 *
 * <PRE>
 * <BR>	修改记录
 * <BR>-----------------------------------------------
 * <BR>	修改日期			修改人			修改内容
 * </PRE>
 *
 * @author liusq23
 * @since 1.0
 * @version 1.0
 */
public class NettyServerRpcHandler extends ChannelInboundHandlerAdapter {


    public void channelRead (ChannelHandlerContext ctx, Object msg) throws Exception {
        if(msg instanceof Invocation){
//            Invocation invocation = (Invocation) msg;
//            String methodName = invocation.methodName();
//            Class<?>[] parameterTypes = invocation.parameterTypes();
//            Object[] args = invocation.getParameters();
//            Method method = this.getService().getClass().getMethod(methodName,parameterTypes);
//            Object result  = method.invoke(service,args);
//            RpcResponse rpcResponse = new RpcResponse(invocation.getToken(),result);
            ctx.writeAndFlush(msg);
        }else{
            ctx.writeAndFlush(msg);
        }
    }


}